package com.example.uilearning;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class SimpleAdaptorActivity extends Activity {
	private ListView listView;
	private String[] names = new String[] { "李希", "李东", "李楠", "李蓓" };
	private String[] desc = new String[] { "在写作业", "在唱歌，lalalallalalalal",
			"我无聊。。。。。。。。。。。。。。。。。", "逛街吧" };
	private int[] imagesId = new int[] { R.drawable.pic1, R.drawable.pic2,
			R.drawable.pic3, R.drawable.pic4 };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_simple_adaptor);
		listView = (ListView) findViewById(R.id.myList);
		// 创建一个List集合,List集合的元素是Map
		List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < names.length; i++) {
			Map<String, Object> listItem = new HashMap<String, Object>();
			listItem.put("header", imagesId[i]);
			listItem.put("personName", names[i]);
			listItem.put("descrption", desc[i]);
			listItems.add(listItem);
		}
		;
		// 创建一个SimpleAdaptor
		SimpleAdapter simpleAdapter = new SimpleAdapter(this, listItems,
				R.layout.simple_item, new String[] { "header", "personName",
						"descrption" }, new int[] { R.id.header, R.id.name,
						R.id.desc });
		System.out.println("Size:"+listItems.size());
		listView.setAdapter(simpleAdapter);
	}
}
